"""7.2  读写 CSV 文件"""
import csv

# 写入 CSV 文件
with open('test.csv', 'w', newline='',encoding="utf8") as file:
    #通过csc文件写入器创建一个对象
    writer = csv.writer(file)
    writer.writerow(['姓名', '年龄', '性别'])
    writer.writerow(['张三', 20, '男'])
    writer.writerow(['李四', 21, '女'])
    writer.writerow(['王五', 22, '男'])
#读取csv文件
with open('test.csv', 'r',encoding="utf8") as file:
    #通过csv文件读取器创建一个对象
    reader = csv.reader(file)
    for row in reader:
        print(row)